package uscdb.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import uscdb.dao.AreaDaoI;
import uscdb.dao.BugTypeDaoI;
import uscdb.dao.ProductDaoI;
import uscdb.dao.VersionDaoI;
import uscdb.model.Tarea;
import uscdb.model.Tbugtype;
import uscdb.model.Tproduct;
import uscdb.model.Tversion;
import uscdb.service.InitServiceI;

@Service
public class InitServiceImpl implements InitServiceI {

	@Autowired
	private ProductDaoI productDao;

	@Autowired
	private VersionDaoI versionDao;

	@Autowired
	private BugTypeDaoI bugTypeDao;

	@Autowired
	private AreaDaoI areaDao;

	@Override
	public void init() {

		/**
		 * 初始化常用的产品信息
		 */
		initProduct();
		/**
		 * 初始化常用的产品版本号
		 */
		initVersionByProduct();

		/**
		 * 初始化 bug 的类型：提示，一般，严重，致命
		 */
		initBugType();// 初始化BUG类型

		initArea();
	}

	private void initArea() {
		{
			Tarea tareaxiou = new Tarea();
			tareaxiou.setId("1");
			tareaxiou.setName("西欧");
			tareaxiou.setDescription("西欧");
			areaDao.saveOrUpdate(tareaxiou);
		}
		{
			Tarea tareadbou = new Tarea();
			tareadbou.setId("2");
			tareadbou.setName("东北欧");
			tareadbou.setDescription("东北欧");
			areaDao.saveOrUpdate(tareadbou);
		}
		{
			Tarea tareanantai = new Tarea();
			tareanantai.setId("3");
			tareanantai.setName("南太");
			tareanantai.setDescription("南太");
			areaDao.saveOrUpdate(tareanantai);
		}
		{
			Tarea tareadnya = new Tarea();
			tareadnya.setId("4");
			tareadnya.setName("东南亚");
			tareadnya.setDescription("东南亚");
			areaDao.saveOrUpdate(tareadnya);
		}
		{
			Tarea tareazhongya = new Tarea();
			tareazhongya.setId("5");
			tareazhongya.setName("中亚");
			tareazhongya.setDescription("中亚");
			areaDao.saveOrUpdate(tareazhongya);
		}
		{
			Tarea tareazhongdong = new Tarea();
			tareazhongdong.setId("6");
			tareazhongdong.setName("中东");
			tareazhongdong.setDescription("中东");
			areaDao.saveOrUpdate(tareazhongdong);
		}
		{
			Tarea tareananfei = new Tarea();
			tareananfei.setId("7");
			tareananfei.setName("南非");
			tareananfei.setDescription("南非");
			areaDao.saveOrUpdate(tareananfei);
		}
		{
			Tarea tareabeifei = new Tarea();
			tareabeifei.setId("8");
			tareabeifei.setName("北非");
			tareabeifei.setDescription("北非");
			areaDao.saveOrUpdate(tareabeifei);
		}
		{
			Tarea tarealamei = new Tarea();
			tarealamei.setId("9");
			tarealamei.setName("拉美");
			tarealamei.setDescription("拉美");
			areaDao.saveOrUpdate(tarealamei);
		}
		{
			Tarea tareachina = new Tarea();
			tareachina.setId("10");
			tareachina.setName("中国");
			tareachina.setDescription("中国");
			areaDao.saveOrUpdate(tareachina);
		}
		{
			Tarea tareameiguo = new Tarea();
			tareameiguo.setId("11");
			tareameiguo.setName("美国");
			tareameiguo.setDescription("美国");
			areaDao.saveOrUpdate(tareameiguo);
		}
		{
			Tarea tareariben = new Tarea();
			tareariben.setId("12");
			tareariben.setName("日本");
			tareariben.setDescription("日本");
			areaDao.saveOrUpdate(tareariben);
		}
		{
			Tarea tareaeluosi = new Tarea();
			tareaeluosi.setId("13");
			tareaeluosi.setName("俄罗斯");
			tareaeluosi.setDescription("俄罗斯");
			areaDao.saveOrUpdate(tareaeluosi);
		}
	}

	private void initBugType() {
		Tbugtype tishi = new Tbugtype();
		tishi.setId("0");
		tishi.setName("提示");
		bugTypeDao.saveOrUpdate(tishi);

		Tbugtype yiban = new Tbugtype();
		yiban.setId("1");
		yiban.setName("一般");
		bugTypeDao.saveOrUpdate(yiban);

		Tbugtype yanzhong = new Tbugtype();
		yanzhong.setId("2");
		yanzhong.setName("严重");
		bugTypeDao.saveOrUpdate(yanzhong);

		Tbugtype zhiming = new Tbugtype();
		zhiming.setId("3");
		zhiming.setName("致命");
		bugTypeDao.saveOrUpdate(zhiming);
	}

	/**
	 * 初始化常用的产品版本号
	 */
	public void initVersionByProduct() {
		Tproduct tproductUPA = productDao.get("from Tproduct t where t.id = '6'");
		Tproduct tproductDSP = productDao.get("from Tproduct t where t.id = '7'");
		Tproduct tproductUSCDB = productDao.get("from Tproduct t where t.id = '5'");

		{
			Tversion tversionUPA173 = new Tversion();
			// 6是UPA的产品ID，1是代表这个产品下的产品号，递增
			tversionUPA173.setId("61");
			tversionUPA173.setName("UPA V100R007C30");
			tversionUPA173.setDescription("该产品目前在XX商用交付");
			tversionUPA173.setTproduct(tproductUPA);
			versionDao.saveOrUpdate(tversionUPA173);
		}
		{
			Tversion tversionUPA175 = new Tversion();
			tversionUPA175.setId("62");
			tversionUPA175.setName("UPA V100R007C50");
			tversionUPA175.setDescription("该产品目前在XX商用交付");
			tversionUPA175.setTproduct(tproductUPA);
			versionDao.saveOrUpdate(tversionUPA175);
		}
		{
			// 本来想写2.0可惜变量不允许这种命名
			Tversion tversionDSP20 = new Tversion();
			// 7是DPS的产品ID，1是代表这个产品下的产品号，递增
			tversionDSP20.setId("71");
			tversionDSP20.setName("DSP2.0");
			tversionDSP20.setDescription("目前该产品在XX进行交付");
			tversionDSP20.setTproduct(tproductDSP);
			versionDao.saveOrUpdate(tversionDSP20);
		}
		{
			Tversion tversionDSP21 = new Tversion();
			tversionDSP21.setId("72");
			tversionDSP21.setName("DSP2.1");
			tversionDSP21.setDescription("目前该产品在XX进行交付");
			tversionDSP21.setTproduct(tproductDSP);
			versionDao.saveOrUpdate(tversionDSP21);
		}
		{
			Tversion tversionUSCDB173 = new Tversion();
			// 5是USCDB的产品ID，1是代表这个产品下的产品号，递增
			tversionUSCDB173.setId("51");
			tversionUSCDB173.setName("USCDB V100R007C30");
			tversionUSCDB173.setDescription("全球商用");
			tversionUSCDB173.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB173);
		}
		{
			Tversion tversionUSCDB175 = new Tversion();
			tversionUSCDB175.setId("52");
			tversionUSCDB175.setName("USCDB V100R007C50");
			tversionUSCDB175.setDescription("全球商用");
			tversionUSCDB175.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB175);
		}
		{
			Tversion tversionUSCDB176 = new Tversion();
			tversionUSCDB176.setId("53");
			tversionUSCDB176.setName("USCDB V100R007C60");
			tversionUSCDB176.setDescription("全球商用");
			tversionUSCDB176.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB176);
		}
		{
			Tversion tversionUSCDB177 = new Tversion();
			tversionUSCDB177.setId("54");
			tversionUSCDB177.setName("USCDB V100R007C70");
			tversionUSCDB177.setDescription("全球商用");
			tversionUSCDB177.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB177);
		}
		{
			Tversion tversionUSCDB5801 = new Tversion();
			tversionUSCDB5801.setId("55");
			tversionUSCDB5801.setName("USCDB V500R008C01");
			tversionUSCDB5801.setDescription("全球商用");
			tversionUSCDB5801.setTproduct(tproductUSCDB);
			tversionUSCDB5801.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB5801);
		}
		{
			Tversion tversionUSCDB581 = new Tversion();
			tversionUSCDB581.setId("56");
			tversionUSCDB581.setName("USCDB V500R008C10");
			tversionUSCDB581.setDescription("全球商用");
			tversionUSCDB581.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB581);
		}
		{
			Tversion tversionUSCDB582 = new Tversion();
			tversionUSCDB582.setId("57");
			tversionUSCDB582.setName("USCDB V500R008C20");
			tversionUSCDB582.setDescription("全球商用");
			tversionUSCDB582.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB582);
		}
		{
			Tversion tversionUSCDB583 = new Tversion();
			tversionUSCDB583.setId("58");
			tversionUSCDB583.setName("USCDB V500R008C30");
			tversionUSCDB583.setDescription("全球商用");
			tversionUSCDB583.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB583);
		}
		{
			Tversion tversionUSCDB5831 = new Tversion();
			tversionUSCDB5831.setId("59");
			tversionUSCDB5831.setName("USCDB V500R008C31");
			tversionUSCDB5831.setDescription("全球商用");
			tversionUSCDB5831.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB5831);
		}
		{
			Tversion tversionUSCDB585 = new Tversion();
			// 因为ID不够用，向前加100，重新开始计数
			tversionUSCDB585.setId("151");
			tversionUSCDB585.setName("USCDB V500R008C50");
			tversionUSCDB585.setDescription("全球商用");
			tversionUSCDB585.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB585);
		}
		{
			Tversion tversionUSCDB586 = new Tversion();
			tversionUSCDB586.setId("152");
			tversionUSCDB586.setName("USCDB V500R008C60");
			tversionUSCDB586.setDescription("全球商用");
			tversionUSCDB586.setTproduct(tproductUSCDB);
			versionDao.saveOrUpdate(tversionUSCDB586);
		}
	}

	/**
	 * 初始化通用的电信产品
	 */
	private void initProduct() {

		{
			Tproduct tproductUSCDB = new Tproduct();
			tproductUSCDB.setId("5");
			tproductUSCDB.setName("USCDB");
			tproductUSCDB.setDescription("融合数据平台数据库USCDB");
			productDao.saveOrUpdate(tproductUSCDB);
		}

		{
			Tproduct tproductUPA = new Tproduct();
			tproductUPA.setId("6");
			tproductUPA.setName("UPA");
			tproductUPA.setDescription("动态用户画像产品UPA");
			productDao.saveOrUpdate(tproductUPA);
		}

		{
			Tproduct tproductDSP = new Tproduct();
			tproductDSP.setId("7");
			tproductDSP.setName("DSP");
			tproductDSP.setDescription("动态用户画像产品DSP");
			productDao.saveOrUpdate(tproductDSP);
		}
		{
			Tproduct tproductUPCC = new Tproduct();
			tproductUPCC.setId("8");
			tproductUPCC.setName("UPCC");
			tproductUPCC.setDescription("UPCC");
			productDao.saveOrUpdate(tproductUPCC);
		}
		{
			Tproduct tproductHSS = new Tproduct();
			tproductHSS.setId("9");
			tproductHSS.setName("HSS");
			tproductHSS.setDescription("HSS");
			productDao.saveOrUpdate(tproductHSS);
		}

		{
			Tproduct tproductUIM = new Tproduct();
			tproductUIM.setId("10");
			tproductUIM.setName("UIM");
			tproductUIM.setDescription("UIM");
			productDao.saveOrUpdate(tproductUIM);
		}
		{
			Tproduct tproductENS = new Tproduct();
			tproductENS.setId("11");
			tproductENS.setName("ENS");
			tproductENS.setDescription("ENS");
			productDao.saveOrUpdate(tproductENS);
		}
		{
			Tproduct tproductIMS = new Tproduct();
			tproductIMS.setId("12");
			tproductIMS.setName("IMS");
			tproductIMS.setName("IMS");
			tproductIMS.setDescription("IMS");
			productDao.saveOrUpdate(tproductIMS);
		}
		{
			Tproduct tproductSDB = new Tproduct();
			tproductSDB.setId("13");
			tproductSDB.setName("SDB");
			tproductSDB.setName("SDB");
			tproductSDB.setDescription("SDB");
			productDao.saveOrUpdate(tproductSDB);
		}

	}

}
